package com.tjetc.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * 自定义拦截器
 *
 *
 * @author gaoyongxiang
 * @version v1.0
 * @date 2025/9/5
 */
@Component
public class MyInterceptor1 implements HandlerInterceptor {

    // handler  你即将要进入的controller
    // 当你不符合某些条件的时候 直接响应 不在请求contoller
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandle1执行");
        return true;
    }

    // 对处理后的内容进行处理
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle1执行");
        int i = 1 / 0;
    }

    // 在执行完的最后 我想要干什么
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("afterCompletion1执行");
        System.out.println(ex.getMessage());
    }
}